<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!--     //页面上输入用户的姓名、性别、年龄 确认后 列表的方式显示添加的数据
        //提示：取出input对应的dom对象后可以通过values属性获取到input中的内容 -->
    <div>
        <input type="text" id="username" />
        <input type="radio" id="sexOne" name="sex" value="男" />男
        <input type="radio" id="sexTwo" checked name="sex" value="女" />女
        <input type="text" id="age" />
        <button id="add">添加</button>
    </div>
    <br />
    <table cellspacing="0" border="1" width="600px">
        <tr>
            <td>姓名</td>
            <td>性别</td>
            <td>年龄</td>
        </tr>
    </table>
    <script>

        var str = `<tr>
                <td>${"姓名"}</td>
                <td>${"性别"}</td>
                <td>${"年龄"}</td>
                </tr>`
        document.querySelector("#add").onclick = function () {
            var name = document.querySelector("#username").value;
            var gender1 = document.querySelector("#sexOne");
            var gender2 = document.querySelector("#sexTwo");
            var age = document.querySelector("#age").value;
            var tab=document.querySelector("table");
            if (gender1.checked == true) {
                var main = `<tr>
                <td>${name}</td>
                <td>${gender1.value}</td>
                <td>${age}</td>
                </tr>`;
                str += main;
            } else {
                var main = `<tr>
                <td>${name}</td>
                <td>${gender2.value}</td>
                <td>${age}</td>
                </tr>`;
                str += main;
            }
            tab.innerHTML = str;
        }
    </script>
</body>

</html>